/**
 * 商家导航详情页面
 * @author Qasim <15750783791@163.com>
 * @version 2016/9/28
 */
var self = phone = id = uid = tid =  '';  

document.addEventListener('plusready' , ready ,  false);

function ready(){
	self = plus.webview.currentWebview();
	var memberInfo = plus.storage.getItem('memberInfo');
	memberInfo = $.parseJSON(memberInfo);
	uid = memberInfo.aid;
	id = self.aid; 
	phone = self.phone;
	tid = self.tid;
	$('.title').text(self.company_name);
	$('.details').text(self.body)
	$('.phone').text(phone);
	$('.contacts').text(self.contacts);
	$('.address').text(self.address);
//	$('.scale').text(self.scale);
//	$('.classify').text(self.classify);
	$('.good').text(self.good);
	$('.number').text(self.number);
	
	
	$('.level span').each(function(index){
		if(self.level > index) $(this).removeClass('color-c')
	})
	
	//留言
	$('.ly').on('click' , function(){
		plus.nativeUI.showWaiting('跳转中...');
		var ly = plus.webview.create('ly.html', 'ly', {}, {
			uid : memberInfo.aid, 
			nickname : memberInfo.nickname,
			aid : id,
			tid : tid,
			title : self.company_name,
		}); 
		ly.addEventListener('loaded', function (){
			ly.show('pop-in');
			plus.nativeUI.closeWaiting();
		})	
	})
	//拨打电话
 	$('.call').on('click' , function(){
 		plus.nativeUI.confirm('温馨提示: 	确定要拨打'+phone+'吗？' , function(e){
 			if(e.index == 0){
 				plus.device.dial(phone , false);
 			}
 		} , '第三方咨询' , ['确定' , '取消'])
 	}) 
 	
 	//下单
 	$('.xiadan').on('tap' , function(){
 		plus.nativeUI.showWaiting('跳转中...');
 		var order_xd_inf = plus.webview.create('order-xd-inf.html', 'order_xd_inf', {}, {
			uid : memberInfo.aid, 
			nickname : memberInfo.nickname,
			aid : id,
			title : self.company_name,
			classify : self.body
		}); 
		order_xd_inf.addEventListener('loaded', function (){
			order_xd_inf.show('pop-in');
			plus.nativeUI.closeWaiting();
		})	
 	}) 
 	
 	//浏览量与收藏状态
 	plus.nativeUI.showWaiting('加载中...');
 	
 	$.ajax({  
 		
		type:"post", 
		
		url:apiRoot + '/Home/Business/collection_status/',
		
		data:{
			uid : uid , 
			aid : id ,
			tid : tid,
			evaluate : 'evaluate'
		},
		
		dataType : 'json',
		
		success : function(data){ 
			
			plus.nativeUI.closeWaiting();  
			
			if(data)$('.collection_status').css('color' , 'darkgoldenrod');
			
//			$('.hits').text(data.hits);
			
		},
		error : function(e){
			console.log(JSON.stringify(e))
			toast('连接超时,请检查网络');
			plus.nativeUI.closeWaiting();
		}
	});
	
	//点击分享
	$('.share').each(function(index) { 
		var type = ex = content = ''  
		$(this).on('click', function() {
			if(index == 0) {type = 'weixin' ; ex = 'WXSceneSession'; content = '';} 
			if(index == 1) {type = 'qq' ; ex = ''; content = $('.content').text() ; } 
			if(index == 2) {type = 'weixin' ; ex = 'WXSceneTimeline';content = '';}
			shareAction(type, ex , id , '端砚生物' , '' , '' , uid , tid);
		})
	})
 	//收藏
 	$('.collection').on('click' , function(){
 		plus.nativeUI.showWaiting('操作中...'); 
 		$.ajax({  
 			type:"post", 
 			url:apiRoot + '/Home/Business/collection/',
 			data:{
 				uid : uid , 
 				aid : id ,
 				tid : tid
 			},
 			success : function(data){ 
 				plus.nativeUI.closeWaiting();  
 				var type = '';
 				if(data == 0){ 
 					toast('已取消');
 					type = '取消收藏';
 					$('.collection_status').css('color' , 'aliceblue');
 				}else{
 					toast('已收藏');
   					$('.collection_status').css('color' , 'darkgoldenrod');
 				}
 				
   				if(self.page){
   					mui.fire(plus.webview.getWebviewById(self.page) , 'cancel' ,{
	 					id : id  ,
	 					type : type
					});

   				}
 			},
 			error : function(e){
 				console.log(JSON.stringify(e))
 				toast('连接超时,请检查网络');
 				plus.nativeUI.closeWaiting();
 			}
 			
 		});
 	})
 	
 	
}
